Whittle away a few more C-style date handlers.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 23 Aug 2013 03:01:02 +0000 (03:01 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 23 Aug 2013 03:01:02 +0000 (03:01 +0000)
gpsbabel/exif.cc
gpsbabel/html.cc
gpsbabel/kml.cc
gpsbabel/skyforce.cc
gpsbabel/text.cc

index 51c48af32891a0a8fecd1996e862b91286549cb3..f449ffbc37cdbc522cb58658696be7c87a327ec9 100644 (file)
@@ -36,7 +36,6 @@
 #include "defs.h"
 #include "garmin_tables.h"
 #include "jeeps/gpsmath.h"
-#include "strptime.h"
 
 #define MYNAME "exif"
 
@@ -649,8 +648,9 @@ exif_find_tag(exif_app_t* app, const uint16_t ifd_nr, const uint16_t tag_id)
 static time_t
 exif_get_exif_time(exif_app_t* app)
 {
+  QDateTime res;
+
   exif_tag_t* tag;
-  time_t res = 0;
 
   tag = exif_find_tag(app, EXIF_IFD, 0x9003);                  /* DateTimeOriginal from EXIF */
   if (! tag) {
@@ -659,20 +659,15 @@ exif_get_exif_time(exif_app_t* app)
   if (! tag) {
     tag = exif_find_tag(app, EXIF_IFD, 0x9004);  /* DateTimeDigitized from EXIF */
   }
+
   if (tag) {
-    struct tm tm;
-    char* c, *str;
+    char* str;
 
-    memset(&tm, 0, sizeof(tm));
     str = exif_read_str(tag);
-    c = strptime(str, "%Y:%m:%d %H:%M:%S", &tm);
-    if (c && (*c == '\0')) {
-      res = mklocaltime(&tm);
-    }
-
+    res = QDateTime::fromString(str, "yyyy:MM:dd hh:mm:ss");
     xfree(str);
   }
-  return res;
+  return res.toTime_t();
 }
 
 static waypoint*
@@ -850,6 +845,7 @@ exif_waypt_from_exif_app(exif_app_t* app)
   } else {
     timestamp = datestamp;
   }
+
   if (timestamp != UNKNOWN_TIMESTAMP) {
 #ifdef EXIF_DBG
     char* str = exif_time_str(timestamp);
index b3688367eda8a91aacef3c884884fa664f8e0415..12c4d65f1bf2a0ff90ed225d4fa550f7a5b6ac77 100644 (file)
@@ -79,9 +79,7 @@ wr_deinit(void)
 static void
 html_disp(const waypoint* wpt)
 {
-  char tbuf[1024];
   char* cout;
-  time_t tm = wpt->GetCreationTime().toTime_t();
   int32_t utmz;
   double utme, utmn;
   char utmzc;
@@ -91,12 +89,6 @@ html_disp(const waypoint* wpt)
   GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude,
                            &utme, &utmn, &utmz, &utmzc);
 
-  if (tm == 0) {
-    tm = time(NULL);
-  }
-  strftime(tbuf, sizeof(tbuf), "%d-%b-%Y", localtime(&tm));
-
-
   gbfprintf(file_out, "\n<a name=\"%s\"><hr></a>\n", wpt->shortname);
   gbfprintf(file_out, "<table width=\"100%%\">\n");
   gbfprintf(file_out, "<tr><td><p class=\"gpsbabelwaypoint\">%s - ",(global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname);
index 91e3ce501b16d1e7454912cd69838074733dd058..3aa5cf5d552965f35c06ed2d2c61aa21eeb7b93e 100644 (file)
@@ -1890,8 +1890,6 @@ void kml_mt_array_schema(const char* field_name, const char* display_name,
 
 void kml_write(void)
 {
-  char import_time[100];
-  time_t now;
   const global_trait* traits = get_traits();
 
   // Parse options
@@ -1920,16 +1918,15 @@ void kml_write(void)
 
   writer->writeStartElement("Document");
 
-  now = current_time().toTime_t();
-  strftime(import_time, sizeof(import_time), "%c", localtime(&now));
   if (realtime_positioning) {
     writer->writeTextElement("name", "GPS position");
   } else {
     writer->writeTextElement("name", "GPS device");
   }
 
-  if (now) {
-    writer->writeTextElement("snippet", QString("Created ") + QString(import_time));
+  if (current_time().isValid()) {
+    writer->writeTextElement("snippet", QString("Created ") + 
+                             current_time().toString());
   }
 
   kml_write_AbstractView();
index 9c447d5e3d8710df23e2d8bb748a5056d4fd9258..47a802a2a66e724c776f25f33fab799021a10ad2 100644 (file)
@@ -26,7 +26,6 @@
 #include <time.h>
 
 #include "defs.h"
-#include "strptime.h"
 
 #define MYNAME "skyforce"
 
@@ -93,7 +92,6 @@ static waypoint*
 skyforce_parse_trk(const char* str)
 {
   char* cx;
-  struct tm tm;
   char buf[15];
   int len;
 
@@ -103,18 +101,14 @@ skyforce_parse_trk(const char* str)
   if (wpt == NULL) {
     return NULL;
   }
-
-  memset(&tm, 0, sizeof(tm));
   strncpy(buf, str + 2, sizeof(buf) - 1);
   buf[14] = 0;
 
-  cx = strptime(buf, "%d%m%y  %H%M%S ", &tm);
-  if ((cx != NULL) && (*cx != '\0')) {
-    fatal(MYNAME ": Could not parse date string (%s - %s).\n", buf, cx);
-  }
-
-  wpt->SetCreationTime(mkgmtime(&tm));
+  QDateTime dt = QDateTime::fromString(buf, "ddMMyy  hhmmss");
+  dt.setTimeSpec(Qt::UTC);
+  dt = dt.addYears(100);
 
+  wpt->SetCreationTime(dt);
   len = strlen(str);
 
   if (len >= 45) {
index 5221d4ca64cda687d0703fffd11e59fc84871ea4..bc25f334fe6e0ca8253c92c2f9f4b1c8c3cc5c9f 100644 (file)
@@ -96,8 +96,8 @@ static void
 text_disp(const waypoint* wpt)
 {
   int latint, lonint;
-  char tbuf[1024];
-  time_t tm = wpt->GetCreationTime().toTime_t();
+//  char tbuf[1024];
+//  time_t tm = wpt->GetCreationTime().toTime_t();
   int32_t utmz;
   double utme, utmn;
   char utmzc;
@@ -118,12 +118,12 @@ text_disp(const waypoint* wpt)
 
   GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude,
                            &utme, &utmn, &utmz, &utmzc);
-
+#if 0
   if (tm == 0) {
     tm = time(NULL);
   }
   strftime(tbuf, sizeof(tbuf), "%d-%b-%Y", localtime(&tm));
-
+#endif
   tmpout1 = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 0);
   if (wpt->altitude != unknown_alt) {
     xasprintf(&altout, " alt:%d", (int)((altunits[0]=='f')?METERS_TO_FEET(wpt->altitude):wpt->altitude));